import { Scene_MenuBase } from "@/scenes/Scene_MenuBase.js";
import { Window_MenuCommand } from "@/windows/Window_MenuCommand.js";
import { Window_Gold } from "@/windows/Window_Gold.js";
import { Window_MenuStatus } from "@/windows/Window_MenuStatus.js";
import { TextManager } from "@/managers/TextManager.js";
import { SceneManager } from "@/managers/SceneManager.js";
import { config } from "@/managers/ConfigManager.js";


import { Scene_Item } from "@/scenes/Scene_Item.js";
import { Scene_Skill } from "@/scenes/Scene_Skill.js";
import { Scene_Equip } from "@/scenes/Scene_Equip.js";
import { Scene_Status } from "@/scenes/Scene_Status.js";
import { Scene_Options } from "@/scenes/Scene_Options.js";
import { Scene_Save } from "@/scenes/Scene_Save.js";
import { Scene_Title } from "@/scenes/Scene_Title.js";

export class Scene_Menu extends Scene_MenuBase {
    constructor() {
        super();
    }

    create() {
        super.create();
        this.createCommandWindow();
        this.createGoldWindow();
        this.createStatusWindow();

        this.attachHandler();
    }

    createCommandWindow() {
        this._commandWindow = new Window_MenuCommand(240, config.height);
        this.addWindow(this._commandWindow);
    }

    createGoldWindow() {
        this._goldWindow = new Window_Gold(240, 72);
        this._goldWindow.y = config.height - this._goldWindow.height;
        this.addWindow(this._goldWindow);
    }

    createStatusWindow() {
        this._statusWindow = new Window_MenuStatus(config.width-240, config.height);
        this._statusWindow.x=240;
        this._statusWindow.deactivate();
       
        this.addWindow(this._statusWindow);
    }

    attachHandler(){
        this._commandWindow.setHandler(TextManager.item,()=>{
            SceneManager.push(Scene_Item);
        });
        this._commandWindow.setHandler(TextManager.options,()=>{
            SceneManager.push(Scene_Options);
        });
        this._commandWindow.setHandler(TextManager.save,()=>{
            SceneManager.push(Scene_Save);
        });
        this._commandWindow.setHandler(TextManager.gameEnd,()=>{
            //SceneManager.push(Scene_GameEnd);
            SceneManager.clearStack();
            SceneManager.goto(Scene_Title);
        });
        this._commandWindow.setHandler('ok',()=>{
            this._commandWindow.deactivate();
            this._statusWindow.activate();
            this._statusWindow.select(0);
        });
        this._commandWindow.setHandler('cancel',()=>{
            SceneManager.pop();
        });


        this._statusWindow.setHandler('ok',actor=>{
            $gameParty.setMenuActor(actor);
            switch (this._commandWindow.currentCommand()) {
                case TextManager.skill:
                    SceneManager.push(Scene_Skill);
                    break;
                case TextManager.equip:
                    SceneManager.push(Scene_Equip);
                    break;
                case TextManager.status:
                    SceneManager.push(Scene_Status);
                    break;
            }
        });
        this._statusWindow.setHandler('cancel', ()=>{
            this._statusWindow.deactivate();
            this._commandWindow.activate();
            this._statusWindow.select(-1);
        });
    }
}